package com.blood.modules.system.controller;

import com.blood.core.resp.PageResult;
import com.blood.core.resp.ResponseResult;
import com.blood.modules.system.dto.req.SysMenuPageReq;
import com.blood.modules.system.dto.req.SysMenuSaveReq;
import com.blood.modules.system.dto.resp.SysMenuInfoResp;
import com.blood.modules.system.dto.resp.SysMenuPageResp;
import com.blood.modules.system.service.ISysMenuService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 菜单权限Controller
 *
 * @author daoren
 * @date 2022-11-23 10:34:28
 */
@Api(value = "菜单权限", tags = "菜单权限")
@ApiSort(999)
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    /**
     * 菜单权限服务.
     */
    @Autowired
    private ISysMenuService sysMenuService;

    /**
     * 分页查询列表
     *
     * @param req
     * @return 分页数据
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "菜单权限列表-分页")
    public ResponseResult<PageResult<SysMenuPageResp>> pageList(@RequestBody SysMenuPageReq req) {
        return sysMenuService.pageList(req);
    }

    /**
     * 添加.
     *
     * @param req 保存参数
     * @return 添加结果
     */
    @ApiOperation(value = "添加菜单权限信息")
    @PostMapping(value = "/add")
    public ResponseResult<Void> add(@RequestBody @Validated SysMenuSaveReq req) {
        return sysMenuService.saveInfo(req);
    }

    /**
     * 修改.
     *
     * @param req 修改参数
     * @return 修改结果
     */
    @ApiOperation(value = "修改菜单权限信息")
    @PostMapping(value = "/update")
    public ResponseResult<Void> update(@RequestBody @Validated SysMenuSaveReq req) {
        return sysMenuService.updateInfo(req);
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return 详情
     */
    @GetMapping("/findDetailById")
    @ApiOperation(value = "获取菜单权限详情")
    public ResponseResult<SysMenuInfoResp> findDetailById(@ApiParam(value = "id", type = "String") @RequestParam("id") String id) {
        return sysMenuService.findDetailById(id);
    }
}
